<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">// Copyright 2011 Bryan McKelvey</span><span class="WHIT">
<span class='line'>  2</span> 
<span class='line'>  3</span> </span><span class="COMM">/**
<span class='line'>  4</span>  * @fileoverview Main background script.
<span class='line'>  5</span>  * @author bryan.mckelvey@gmail.com (McKelvey Bryan)
<span class='line'>  6</span>  */</span><span class="WHIT">
<span class='line'>  7</span> 
<span class='line'>  8</span> </span><span class="COMM">/**
<span class='line'>  9</span>  * Background script functions.
<span class='line'> 10</span>  * @namespace Background script functions.
<span class='line'> 11</span>  */</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">Background</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 13</span> </span><span class="WHIT"> 
<span class='line'> 14</span>   </span><span class="COMM">/**
<span class='line'> 15</span>    * List of main sources for links. Used to determine which picture to show on ESPN scoreboard.
<span class='line'> 16</span>    * @type {Array.&lt;RegExp,string>}
<span class='line'> 17</span>    * @final
<span class='line'> 18</span>    */</span><span class="WHIT">
<span class='line'> 19</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">SCHOOL_NAME_STANDARDIZATIONS</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="WHIT">
<span class='line'> 20</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="REGX">/n(?:orth)?(?:ern)?\.?\s/</span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'n '</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 21</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="REGX">/s(?:outh)?(?:ern)?\.?\s/</span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'s '</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 22</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="REGX">/east(?:ern)?\s/</span><span class="PUNC">,</span><span class="WHIT">            </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'e '</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 23</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="REGX">/west(?:ern)?\s/</span><span class="PUNC">,</span><span class="WHIT">            </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'w '</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 24</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'state'</span><span class="PUNC">,</span><span class="WHIT">                     </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'st'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 25</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'saint '</span><span class="PUNC">,</span><span class="WHIT">                    </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'st '</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 26</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'university'</span><span class="PUNC">,</span><span class="WHIT">                </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'u'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 27</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'brigham young'</span><span class="PUNC">,</span><span class="WHIT">             </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'byu'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 28</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="REGX">/^connecticut$/</span><span class="PUNC">,</span><span class="WHIT">             </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'uconn'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 29</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'georgia'</span><span class="PUNC">,</span><span class="WHIT">                   </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'ga'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 30</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'mississippi'</span><span class="PUNC">,</span><span class="WHIT">               </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'miss'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 31</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'marymount'</span><span class="PUNC">,</span><span class="WHIT">                 </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'mary'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 32</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'n carolina'</span><span class="PUNC">,</span><span class="WHIT">                </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'nc'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'s carolina'</span><span class="PUNC">,</span><span class="WHIT">                </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'sc'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'texas'</span><span class="PUNC">,</span><span class="WHIT">                     </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'tx'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'virginia'</span><span class="PUNC">,</span><span class="WHIT">                  </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'va'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 36</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'illinois-chicago'</span><span class="PUNC">,</span><span class="WHIT">          </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'uic'</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 37</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="REGX">/\-/g</span><span class="PUNC">,</span><span class="WHIT">                       </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">' '</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 38</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="REGX">/\./g</span><span class="PUNC">,</span><span class="WHIT">                       </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 39</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="NAME">search</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="REGX">/^\s+|\s+$/g</span><span class="PUNC">,</span><span class="WHIT">                </span><span class="NAME">replacement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 40</span> </span><span class="WHIT">  </span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 41</span> 
<span class='line'> 42</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 43</span>    * List of main sources for links. Used to determine which picture to show on ESPN scoreboard.
<span class='line'> 44</span>    * @type {Object.&lt;string>}
<span class='line'> 45</span>    * @final
<span class='line'> 46</span>    */</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">STREAM_SOURCES</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT">    </span><span class="STRN">'ESPN3'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'espn.go.com'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 49</span> </span><span class="WHIT">    </span><span class="STRN">'StreamTorrent'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'st://'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT">    </span><span class="STRN">'TVU'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'tvu://'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="WHIT">    </span><span class="STRN">'CBS Sports'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'cbssports.com'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT">    </span><span class="STRN">'Directon.tv'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'directon.tv'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT">    </span><span class="STRN">'Justin.tv'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'justin.tv'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT">    </span><span class="STRN">'ohlulz'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'ohlulz.com'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">    </span><span class="STRN">'Veetle'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'veetle.com'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT">    </span><span class="STRN">'B2TV'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'b2tv.com'</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">    </span><span class="STRN">'RTMP'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'rtmp://'</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 59</span> 
<span class='line'> 60</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 61</span>    * Default settings for local storage.
<span class='line'> 62</span>    * @type {Object.&lt;boolean>}
<span class='line'> 63</span>    * @final
<span class='line'> 64</span>    */</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">DEFAULT_SETTINGS</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">    </span><span class="STRN">'showEspn3'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 68</span> 
<span class='line'> 69</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 70</span>    * The base URL for the Myp2p forums.
<span class='line'> 71</span>    * @type {string}
<span class='line'> 72</span>    * @final
<span class='line'> 73</span>    */</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MYP2P_FORUM_BASE_URL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'http://www.myp2pforum.eu/'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT">   
<span class='line'> 76</span>   </span><span class="COMM">/**
<span class='line'> 77</span>    * The URL for which we look up the appropriate NCAA thread.
<span class='line'> 78</span>    * @type {string}
<span class='line'> 79</span>    * @final
<span class='line'> 80</span>    */</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MYP2P_FORUM_NCAA_URL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'forums/33-NCAA'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 82</span> 
<span class='line'> 83</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 84</span>    * Determines whether a thread contains NCAA basketball info and extracts the date range into backrefs 1-4.
<span class='line'> 85</span>    * @type {RegExp}
<span class='line'> 86</span>    * @final
<span class='line'> 87</span>    */</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">BASKETBALL_REGEX</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="REGX">/ncaa\-basketball\-([a-z]{3,4})\-([12][0-9]|3[0-1]|[1-9])\-([a-z]{3,4})\-([12][0-9]|3[0-1]|[1-9])/i</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 89</span> 
<span class='line'> 90</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 91</span>    * Determines whether a text node contains game stream information.
<span class='line'> 92</span>    * @type {RegExp}
<span class='line'> 93</span>    * @final
<span class='line'> 94</span>    */</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">GAME_REGEX</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="REGX">/\s+(?:0[1-9]|1[0-2])\:[0-5][0-9]\s[ap]m\s\|/i</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 96</span> 
<span class='line'> 97</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 98</span>    * Determines the names of the teams playing in a game.
<span class='line'> 99</span>    * @type {RegExp}
<span class='line'>100</span>    * @final
<span class='line'>101</span>    */</span><span class="WHIT">
<span class='line'>102</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">TEAMS_REGEX</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="REGX">/\|\s(?:\#(?:1[0-9]|2[0-5]|[1-9])\s)?(.*?)\s(?:vs\.|\@|at)\s(?:\#(?:1[0-9]|2[0-5]|[1-9])\s)?(.*?)(?:\s\||$)/i</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>103</span> 
<span class='line'>104</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>105</span>    * Included for backwards compatibility with IE, which doesn't understand Node.TEXT_NODE.
<span class='line'>106</span>    * @type {number}
<span class='line'>107</span>    * @final
<span class='line'>108</span>    */</span><span class="WHIT">
<span class='line'>109</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">TEXT_NODE_TYPE</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>110</span> 
<span class='line'>111</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>112</span>    * Maximum number of nodes forward to search for links
<span class='line'>113</span>    * @type {number}
<span class='line'>114</span>    * @final
<span class='line'>115</span>    */</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MAX_LINK_ITER</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">10</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>117</span> 
<span class='line'>118</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>119</span>    * Denotes the first match in a regular expression.
<span class='line'>120</span>    * @type {number}
<span class='line'>121</span>    * @final
<span class='line'>122</span>    */</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">FIRST_MATCH</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>124</span> 
<span class='line'>125</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>126</span>    * List of games discovered.
<span class='line'>127</span>    * @type {Object}
<span class='line'>128</span>    */</span><span class="WHIT">
<span class='line'>129</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">gameList</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>130</span> 
<span class='line'>131</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>132</span>    * Script is done looking through threads.
<span class='line'>133</span>    * @type {boolean}
<span class='line'>134</span>    */</span><span class="WHIT">
<span class='line'>135</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">threadSearchDone</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>136</span> 
<span class='line'>137</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>138</span>    * Script is done looking through games in threads it's found.
<span class='line'>139</span>    * @type {boolean}
<span class='line'>140</span>    */</span><span class="WHIT">
<span class='line'>141</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">gameSearchDone</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>142</span> 
<span class='line'>143</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>144</span>    * Total number of threads found.
<span class='line'>145</span>    * @type {number}
<span class='line'>146</span>    */</span><span class="WHIT">
<span class='line'>147</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">threadsFound</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>148</span> 
<span class='line'>149</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>150</span>    * Total number of threads searched through.
<span class='line'>151</span>    * @type {number}
<span class='line'>152</span>    */</span><span class="WHIT">
<span class='line'>153</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">threadsSearched</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>154</span> 
<span class='line'>155</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>156</span>    * Gets the type of stream so an icon can be chosen for display on ESPN's scoreboard
<span class='line'>157</span>    * @param {string} url The stream's url.
<span class='line'>158</span>    * @return {string} The type of stream.
<span class='line'>159</span>    */</span><span class="WHIT">
<span class='line'>160</span> </span><span class="WHIT">  </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">getStreamType</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>161</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">temp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'Other'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>162</span> </span><span class="WHIT">    </span><span class="NAME">$.each</span><span class="PUNC">(</span><span class="NAME">STREAM_SOURCES</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">search</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>163</span> </span><span class="WHIT">      </span><span class="COMM">// If a match is found, set temp to that type and break the loop</span><span class="WHIT">
<span class='line'>164</span> </span><span class="WHIT">      </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">url.indexOf</span><span class="PUNC">(</span><span class="NAME">search</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>165</span> </span><span class="WHIT">        </span><span class="NAME">temp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">type</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>167</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>168</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">temp</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>171</span> 
<span class='line'>172</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>173</span>    * Standardizes the names of schools due to different spelling conventions for 'North/South/East/West,' 'State,' etc.
<span class='line'>174</span>    * @param {string} school The unstandardized name of the school.
<span class='line'>175</span>    * @return {string} The standardized name of the school.
<span class='line'>176</span>    */</span><span class="WHIT">
<span class='line'>177</span> </span><span class="WHIT">  </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">standardizeSchoolName</span><span class="PUNC">(</span><span class="NAME">school</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>178</span> </span><span class="WHIT">    </span><span class="NAME">school</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">school.toLowerCase</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>179</span> </span><span class="WHIT">    </span><span class="NAME">$.each</span><span class="PUNC">(</span><span class="NAME">SCHOOL_NAME_STANDARDIZATIONS</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">index</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">standardization</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>180</span> </span><span class="WHIT">      </span><span class="NAME">school</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">school.replace</span><span class="PUNC">(</span><span class="NAME">standardization.search</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">standardization.replacement</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>181</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>182</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">school</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>183</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>184</span> 
<span class='line'>185</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>186</span>    * Loads NCAA basketball-relevant threads and parses their content for games.
<span class='line'>187</span>    * @param {string} url The path to the thread, excluding the domain name defined in MYP2P_FORUM_BASE_URL.
<span class='line'>188</span>    */</span><span class="WHIT">
<span class='line'>189</span> </span><span class="WHIT">  </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">searchForGames</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>190</span> </span><span class="WHIT">    </span><span class="NAME">$.ajax</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>191</span> </span><span class="WHIT">      </span><span class="NAME">url</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">MYP2P_FORUM_BASE_URL</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">url</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>192</span> </span><span class="WHIT">      </span><span class="NAME">success</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>193</span> </span><span class="WHIT">        </span><span class="NAME">$</span><span class="PUNC">(</span><span class="STRN">'blockquote.postcontent:not(:contains("Women"))'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">contents</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">filter</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.nodeType</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">TEXT_NODE_TYPE</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">each</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>194</span> </span><span class="WHIT">          </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">GAME_REGEX.test</span><span class="PUNC">(</span><span class="NAME">$</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">text</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>195</span> </span><span class="WHIT">            </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">teams</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">TEAMS_REGEX.exec</span><span class="PUNC">(</span><span class="NAME">$</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">text</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>196</span> </span><span class="WHIT">            
<span class='line'>197</span>             </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">teams</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>198</span> </span><span class="WHIT">              </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">standardizeSchoolName</span><span class="PUNC">(</span><span class="NAME">teams</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>199</span> </span><span class="WHIT">              </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">b</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">standardizeSchoolName</span><span class="PUNC">(</span><span class="NAME">teams</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>200</span> 
<span class='line'>201</span> </span><span class="WHIT">              </span><span class="COMM">// Set team that comes first alphabetically as first team</span><span class="WHIT">
<span class='line'>202</span> </span><span class="WHIT">              </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">firstTeam</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>203</span> </span><span class="WHIT">              </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">secondTeam</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>204</span> 
<span class='line'>205</span> </span><span class="WHIT">              </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">b</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>206</span> </span><span class="WHIT">                </span><span class="NAME">firstTeam</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>207</span> </span><span class="WHIT">                </span><span class="NAME">secondTeam</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">b</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>208</span> </span><span class="WHIT">              </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>209</span> </span><span class="WHIT">                </span><span class="NAME">firstTeam</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">b</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>210</span> </span><span class="WHIT">                </span><span class="NAME">secondTeam</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>211</span> </span><span class="WHIT">              </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>212</span> 
<span class='line'>213</span> </span><span class="WHIT">              </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">links</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>214</span> </span><span class="WHIT">              </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>215</span> </span><span class="WHIT">              </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">node</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.nextSibling</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>216</span> </span><span class="WHIT">              </span><span class="KEYW">while</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">node</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">TEAMS_REGEX.test</span><span class="PUNC">(</span><span class="NAME">$</span><span class="PUNC">(</span><span class="NAME">node</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">text</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">MAX_LINK_ITER</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>217</span> </span><span class="WHIT">                </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">href</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">$</span><span class="PUNC">(</span><span class="NAME">node</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">attr</span><span class="PUNC">(</span><span class="STRN">'href'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>218</span> </span><span class="WHIT">                </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">href</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>219</span> </span><span class="WHIT">                  </span><span class="NAME">links.push</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="NAME">type</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">getStreamType</span><span class="PUNC">(</span><span class="NAME">href</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">url</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">href</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>220</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>221</span> </span><span class="WHIT">                </span><span class="NAME">node</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">node.nextSibling</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>222</span> </span><span class="WHIT">              </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>223</span> </span><span class="WHIT">              </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">gameList</span><span class="PUNC">[</span><span class="NAME">firstTeam</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>224</span> </span><span class="WHIT">                </span><span class="NAME">gameList</span><span class="PUNC">[</span><span class="NAME">firstTeam</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>225</span> </span><span class="WHIT">              </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>226</span> </span><span class="WHIT">              </span><span class="NAME">gameList</span><span class="PUNC">[</span><span class="NAME">firstTeam</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NAME">secondTeam</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">links</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>227</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>228</span> </span><span class="WHIT">          </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>229</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>230</span> </span><span class="WHIT">        </span><span class="NAME">threadsSearched</span><span class="PUNC">++</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>231</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">threadsSearched</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="NAME">threadsFound</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>232</span> </span><span class="WHIT">          </span><span class="NAME">gameSearchDone</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>233</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>234</span> </span><span class="WHIT">        </span><span class="NAME">console.log</span><span class="PUNC">(</span><span class="NAME">gameList</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>235</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>236</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>237</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>238</span> 
<span class='line'>239</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>240</span>    * Loads the basketball forum URL and looks for threads that contain NCAA basketball stream information.
<span class='line'>241</span>    */</span><span class="WHIT">
<span class='line'>242</span> </span><span class="WHIT">  </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">searchForThread</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>243</span> </span><span class="WHIT">    </span><span class="NAME">$.ajax</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>244</span> </span><span class="WHIT">      </span><span class="NAME">url</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">MYP2P_FORUM_BASE_URL</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">MYP2P_FORUM_NCAA_URL</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>245</span> </span><span class="WHIT">      </span><span class="NAME">success</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>246</span> </span><span class="WHIT">        </span><span class="NAME">$</span><span class="PUNC">(</span><span class="STRN">'li.threadbit a.title'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">each</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>247</span> </span><span class="WHIT">          </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">url</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">$</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">attr</span><span class="PUNC">(</span><span class="STRN">'href'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>248</span> </span><span class="WHIT">          </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">dates</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">BASKETBALL_REGEX.exec</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>249</span> </span><span class="WHIT">          </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">dates</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>250</span> </span><span class="WHIT">            </span><span class="NAME">threadsFound</span><span class="PUNC">++</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>251</span> </span><span class="WHIT">            </span><span class="NAME">searchForGames</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>252</span> </span><span class="WHIT">          </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>253</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>254</span> </span><span class="WHIT">        </span><span class="NAME">threadSearchDone</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>255</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>256</span> </span><span class="WHIT">      </span><span class="NAME">error</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>257</span> </span><span class="WHIT">        </span><span class="COMM">// error handler</span><span class="WHIT">
<span class='line'>258</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>259</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>260</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>261</span> 
<span class='line'>262</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>263</span>    * Listens for requests from content scripts.
<span class='line'>264</span>    * @param {Object.&lt;string>} request Request sent from the content script.
<span class='line'>265</span>    * @param {Object} sender blah.
<span class='line'>266</span>    * @sendResponse {Object.&lt;string>} sender Return values to the content script.
<span class='line'>267</span>    * @return {string} Some return value.
<span class='line'>268</span>    */</span><span class="WHIT">
<span class='line'>269</span> </span><span class="WHIT">  </span><span class="NAME">chrome.extension.onRequest.addListener</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">request</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">sender</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">sendResponse</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>270</span> </span><span class="WHIT">    </span><span class="KEYW">switch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">request.type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>271</span> </span><span class="WHIT">      </span><span class="KEYW">case</span><span class="WHIT"> </span><span class="STRN">'done'</span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>272</span> </span><span class="WHIT">        </span><span class="NAME">sendResponse</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="NAME">done</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">gameSearchDone</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>273</span> </span><span class="WHIT">        </span><span class="KEYW">break</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>274</span> </span><span class="WHIT">      </span><span class="KEYW">case</span><span class="WHIT"> </span><span class="STRN">'games'</span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>275</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">standardizeSchoolName</span><span class="PUNC">(</span><span class="NAME">request.teams</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>276</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">b</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">standardizeSchoolName</span><span class="PUNC">(</span><span class="NAME">request.teams</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>277</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">links</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>278</span> </span><span class="WHIT">        
<span class='line'>279</span>         </span><span class="COMM">// Set team that comes first alphabetically as first team</span><span class="WHIT">
<span class='line'>280</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">firstTeam</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>281</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">secondTeam</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>282</span> 
<span class='line'>283</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">b</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>284</span> </span><span class="WHIT">          </span><span class="NAME">firstTeam</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>285</span> </span><span class="WHIT">          </span><span class="NAME">secondTeam</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">b</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>286</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>287</span> </span><span class="WHIT">          </span><span class="NAME">firstTeam</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">b</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>288</span> </span><span class="WHIT">          </span><span class="NAME">secondTeam</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>289</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>290</span> 
<span class='line'>291</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">gameList</span><span class="PUNC">[</span><span class="NAME">firstTeam</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>292</span> </span><span class="WHIT">          </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">gameList</span><span class="PUNC">[</span><span class="NAME">firstTeam</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NAME">secondTeam</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>293</span> </span><span class="WHIT">            </span><span class="NAME">sendResponse</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="NAME">links</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">gameList</span><span class="PUNC">[</span><span class="NAME">firstTeam</span><span class="PUNC">]</span><span class="PUNC">[</span><span class="NAME">secondTeam</span><span class="PUNC">]</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>294</span> </span><span class="WHIT">          </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>295</span> </span><span class="WHIT">            </span><span class="NAME">sendResponse</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="NAME">links</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>296</span> </span><span class="WHIT">          </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>297</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>298</span> </span><span class="WHIT">          </span><span class="NAME">sendResponse</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="NAME">links</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>299</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>300</span> </span><span class="WHIT">        </span><span class="KEYW">break</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>301</span> </span><span class="WHIT">      </span><span class="KEYW">case</span><span class="WHIT"> </span><span class="STRN">'settings'</span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>302</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">temp</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>303</span> 
<span class='line'>304</span> </span><span class="WHIT">        </span><span class="COMM">// Get settings from local storage</span><span class="WHIT">
<span class='line'>305</span> </span><span class="WHIT">        </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">key</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">localStorage</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>306</span> </span><span class="WHIT">          </span><span class="NAME">temp</span><span class="PUNC">[</span><span class="NAME">key</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">JSON.parse</span><span class="PUNC">(</span><span class="NAME">localStorage</span><span class="PUNC">[</span><span class="NAME">key</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>307</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>308</span> 
<span class='line'>309</span> </span><span class="WHIT">        </span><span class="NAME">sendResponse</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="NAME">settings</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">temp</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>310</span> </span><span class="WHIT">        </span><span class="KEYW">break</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>311</span> </span><span class="WHIT">      </span><span class="KEYW">default</span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>312</span> </span><span class="WHIT">        </span><span class="NAME">sendResponse</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>313</span> </span><span class="WHIT">        </span><span class="KEYW">break</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>314</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>315</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>316</span> 
<span class='line'>317</span> </span><span class="WHIT">  </span><span class="COMM">// Listen for any changes to the URL of any tab.</span><span class="WHIT">
<span class='line'>318</span> </span><span class="WHIT">  </span><span class="NAME">chrome.tabs.onUpdated.addListener</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">tabId</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">changeInfo</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">tab</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>319</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">tab.url.indexOf</span><span class="PUNC">(</span><span class="STRN">'scores.espn.go.com'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>320</span> </span><span class="WHIT">      </span><span class="NAME">chrome.pageAction.show</span><span class="PUNC">(</span><span class="NAME">tabId</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>321</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>322</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>323</span> 
<span class='line'>324</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>325</span>    * Retrieves settings and, if necessary, restores defaults.
<span class='line'>326</span>    */</span><span class="WHIT">
<span class='line'>327</span> </span><span class="WHIT">  </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">getSettings</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>328</span> </span><span class="WHIT">    </span><span class="COMM">// Set any blank settings to their defaults</span><span class="WHIT">
<span class='line'>329</span> </span><span class="WHIT">    </span><span class="NAME">$.each</span><span class="PUNC">(</span><span class="NAME">DEFAULT_SETTINGS</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">key</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>330</span> </span><span class="WHIT">      </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">localStorage</span><span class="PUNC">[</span><span class="NAME">key</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>331</span> </span><span class="WHIT">        </span><span class="NAME">localStorage</span><span class="PUNC">[</span><span class="NAME">key</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">JSON.stringify</span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>332</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>333</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>334</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>335</span> 
<span class='line'>336</span> </span><span class="WHIT">  </span><span class="NAME">searchForThread</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>337</span> </span><span class="WHIT">  </span><span class="NAME">getSettings</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>338</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>